<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <li :class="{ completed: item.isDone }" v-for="item in list" :key="item.id">
      <div class="view">
        <input
          class="toggle"
          type="checkbox"
          @change="checkedId(item.id)"
          :checked="item.isDone"
        />
        <label>{{ item.name }}</label>
        <button class="destroy" @click="deleteId(item.id)"></button>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  props: {
    // 接收父组件传递过来的数据
    list: {
      type: Array,
      required: true,
    },
  },
  methods: {
    // 给复选框绑定change事件，一但发生改变就把当前项的id传递给父组件
    checkedId(id) {
      this.$emit("checkedId", id);
    },
    // 点击删除把id传递给父亲
    deleteId(id) {
      this.$emit("deleteById", id);
    },
  },
};
</script>